package hw524919.lesson2;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

public class DateNumber {
	private String readString;
	public DateNumber(){
		readString();
	}
	
	private void readString(){
		BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));
		try{
			System.out.print("input date example 2016-01-01");
			readString=bReader.readLine();
		}catch(Exception e){
			e.printStackTrace();
			readString=null;
		}
	}
	
	public boolean getdateNumber(){
		if(StringUtils.isEmpty(readString)) return false;
		SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(false);
		Date date=null;
		try {
			date = dateFormat.parse(readString);
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			System.out.println("本年中的第" + cal.get(Calendar.DAY_OF_YEAR) +"天");
			return true;
		} catch (ParseException e) {
			System.out.println("日期格式错误，请重新调用");
			return false;
		}
	}
}
